home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / PICSee Dust 1.01 / Quaternary Source / CP_DATA.H < prev    next >
Text File  |  1995-11-30  |  6KB  |  260 lines

  1. #ifndef CP_DATA_H_
  2. #define CP_DATA_H_
  3.  
  4. /*
  5.     Cross-platform types & defs
  6.  
  7.     Written by Hiep Dam
  8.     July 1995
  9.     Version 1.1
  10. */
  11.  
  12. /*
  13.     Notes on the Cross-Platform Data types (CP_x):
  14.     
  15.     These data types are defined so that you can use the same data structures
  16.     across different platforms. For example, on the Macintosh rectangles are
  17.     defined as "Rect" while on Windows they're defined as "RECT". So porting
  18.     from one platform to another is troublesome and lots of work. So here
  19.     we define one "CP_Rect" which can be used for all platforms. Internally,
  20.     they'll be defined identically to their platform-specific data structure
  21.     counterparts. So on a Mac the CP_Rect will be internally identical to the
  22.     Rect structure, while on Windows they'll be identical to the RECT struct.
  23.  
  24.     There are some caveats, however:
  25.         1) Don't assume the size of the structure is a certain value if
  26.            you're writing code that you expect will be ported.
  27.  
  28.            In other words, don't hardcode the sizes;
  29.            use "sizeof()" instead.
  30.  
  31.            For example, don't assume the size of a CP_Point is 4 bytes
  32.            (2 shorts). On Windows 32, a CP_Point is 8 bytes (2 longs).
  33.         
  34.         2) Don't assume the order of the members in the structure.
  35.  
  36.            On the Macintosh, v is defined before h. On Windows,
  37.            h is defined before v. For the most part, this shouldn't
  38.            be a problem: the only time you need to know the order
  39.            of the members is when you're using assembly language,
  40.            and this won't be portable anyway.
  41. */
  42.  
  43. // ---------------------------------------------------------------------------
  44.  
  45. // Platform macros
  46.  
  47. #if defined(__FLAT__)
  48.     #define __Windows32_Platform__
  49.  
  50. #elif defined(_Windows)
  51.     #define __Windows16_Platform__
  52.  
  53. #elif defined(__MSDOS__)
  54.     #define __MSDOS_Platform__
  55.  
  56. #elif defined(powerc) || defined(__powerc)            // PowerPC
  57.     #define __Macintosh_Platform__
  58.  
  59. #elif defined(__MWERKS__) || defined(__MC68K__)        // MetroWerks
  60.     #define __Macintosh_Platform__
  61.  
  62. #elif defined(__THINK__) || defined(__SC__)            // Symantec/THINK
  63.     #define __Macintosh_Platform__
  64. #endif
  65.  
  66.  
  67. // Compiler macros
  68.  
  69. #if defined(__Macintosh_Platform__)
  70.     #if defined(__MWERKS__)
  71.         #define __MetroWerks_Compiler__
  72.     #elif defined(__THINK__) || (__SC__)
  73.         #define __Symantec_Compiler__
  74.     #endif
  75. #elif defined(__Windows16_Platform__)
  76.     // None yet...
  77. #endif
  78.  
  79.  
  80. // Instruction set macros
  81.  
  82. #if defined(__Macintosh_Platform__)
  83.     #if defined(powerc) || defined(__powerc)
  84.         #define __ISA_PowerPC__
  85.     #else
  86.         #define __ISA_M68K__
  87.     #endif
  88. #else
  89.     #define __ISA_x86__
  90. #endif
  91.  
  92. // ---------------------------------------------------------------------------
  93.  
  94. // Assembly macros. Currently for Macintosh only.
  95.  
  96. #if defined(__Macintosh_Platform__)
  97.  
  98.     #if defined(__MetroWerks_Compiler__)
  99.         #define ASM_FUNC    asm
  100.         #define ASM_BEGIN
  101.         #define ASM_END
  102.     
  103.     #elif defined(__Symantec_Compiler__)    
  104.         #define ASM_FUNC
  105.         #define ASM_BEGIN    asm {
  106.         #define ASM_END        }
  107.     
  108.     #endif
  109. #endif // __Macintosh_Platform__
  110.  
  111. // ---------------------------------------------------------------------------
  112.  
  113. typedef signed char        CP_SChar;
  114. typedef unsigned char    CP_UChar;
  115.  
  116. typedef signed short    CP_SShort;
  117. typedef unsigned short    CP_UShort;
  118.  
  119. typedef signed long        CP_SLong;
  120. typedef unsigned long    CP_ULong;
  121.  
  122. typedef CP_SChar        CP_Char;
  123. typedef CP_SShort        CP_Short;
  124. typedef CP_SLong        CP_Long;
  125.  
  126. // I can't understand why people use int's at all...
  127. typedef CP_SShort        CP_SInt16;
  128. typedef CP_UShort        CP_UInt16;
  129.  
  130. typedef CP_SLong        CP_SInt32;
  131. typedef CP_ULong        CP_UInt32;
  132.  
  133. // ---------------------------------------------------------------------------
  134.  
  135. /*
  136.     Windows 16 Platform (Windows 3.1)
  137. */
  138.  
  139. #if defined(__Windows16_Platform__)
  140.     #pragma message("Windows 16 platform version used...")
  141.  
  142.     typedef RECT CP_Rect;
  143.  
  144.     typedef POINT CP_Point_XY;
  145.  
  146.     typedef struct {
  147.         int h;
  148.         int v;
  149.     } CP_Point_HV;
  150.  
  151.     typedef union {
  152.         CP_Point_XY xy;
  153.         CP_Point_HV hv;
  154.     } CP_Point;
  155.  
  156.     typedef HRGN CP_Region_Hdl;
  157.     typedef HWND CP_Window_Ref;
  158.     typedef HWND CP_OutputDevice_Ref;
  159.  
  160.     #define nil        NULL
  161.     #define null    NULL
  162.     #define true    TRUE
  163.     #define false    FALSE
  164.  
  165.     #define CP_Point2Point(pt)        (*(POINT*)(&pt))
  166.     #define Point2CP_Point(pt)        (*(CP_Point*)(&pt))
  167.     #define Point2CP_Point_XY(pt)    (*(CP_Point_XY*)(&pt))
  168.     #define Point2CP_Point_HV(pt)    (*(CP_Point_HV*)(&pt))
  169.  
  170.     #define LPARAM2CP_Point(lParam, destPt) Point2CP_Point(destPt) = \
  171.                                             Point2CP_Point(MAKEPOINT(lParam))
  172.  
  173. // ---------------------------------------------------------------------------
  174.  
  175. /*
  176.     Windows 32 Platform (Windows 32s, Windows NT, Windows 95)
  177. */
  178.  
  179. #elif defined(__Windows32_Platform__)
  180.     #pragma message("Windows 32 platform version used...")
  181.  
  182.     typedef RECT CP_Rect;
  183.  
  184.     typedef POINT CP_Point_XY;
  185.  
  186.     typedef struct {
  187.         long h;
  188.         long v;
  189.     } CP_Point_HV;
  190.  
  191.     typedef union {
  192.         CP_Point_XY xy;
  193.         CP_Point_HV hv;
  194.     } CP_Point;
  195.  
  196.     typedef HRGN CP_Region_Hdl;
  197.     typedef HWND CP_Window_Ref;
  198.     typedef HWND CP_OutputDevice_Ref;
  199.  
  200.     #define nil        NULL
  201.     #define null    NULL
  202.     #define true    TRUE
  203.     #define false    FALSE
  204.  
  205.     #define CP_Point2Point(pt)        (*(POINT*)(&pt))
  206.     #define Point2CP_Point(pt)        (*(CP_Point*)(&pt))
  207.     #define Point2CP_Point_XY(pt)    (*(CP_Point_XY*)(&pt))
  208.     #define Point2CP_Point_HV(pt)    (*(CP_Point_HV*)(&pt))
  209.  
  210.     #define LPARAM2CP_Point(lParam, destPt) destPt.xy.x = LOWORD(lParam);\
  211.                                             destPt.xy.y = HIWORD(lParam)
  212.  
  213. // ---------------------------------------------------------------------------
  214.  
  215. /*
  216.     Macintosh and MS-DOS Platforms
  217. */
  218.  
  219. #elif defined(__Macintosh_Platform__) || defined(__MSDOS_Platform__)
  220.  
  221.     #ifdef __MSDOS_Platform__
  222.         #pragma message("MS-DOS platform version used...")
  223.     #else
  224.         //#pragma message("Macintosh platform version used...")
  225.     #endif // __MSDOS_Platform
  226.  
  227.     typedef Rect CP_Rect;
  228.  
  229.     typedef struct {
  230.         short y;
  231.         short x;
  232.     } CP_Point_XY;
  233.  
  234.     typedef Point CP_Point_HV;
  235.  
  236.     typedef union {
  237.         CP_Point_XY xy;
  238.         CP_Point_HV hv;
  239.     } CP_Point;
  240.  
  241.     typedef RgnHandle CP_Region_Hdl;
  242.     typedef WindowPtr CP_Window_Ref;
  243.     typedef GDHandle  CP_OutputDevice_Ref;
  244.  
  245.     #define CP_Point2Point(pt)        (*(Point*)(&pt))
  246.     #define Point2CP_Point(pt)        (*(CP_Point*)(&pt))
  247.     #define Point2CP_Point_XY(pt)    (*(CP_Point_XY*)(&pt))
  248.     #define Point2CP_Point_HV(pt)    (*(CP_Point_HV*)(&pt))
  249. #endif // defined(__Macintosh_Platform__) || defined(__MSDOS_Platform__)
  250.  
  251. // ---------------------------------------------------------------------------
  252.  
  253. /*
  254.     Some useful macros
  255. */
  256.  
  257. #define CP_CopyPoint(srcPt, destPt)    CP_Point2Point(destPt) = \
  258.                                     CP_Point2Point(srcPt)
  259.  
  260. #endif // CP_DATA_H_